<?php
require_once 'database.php';

//return all the cities
function getVille(){
	$query="select distinct ville from residence ";
	$result=runQuery($query);
	$villes="";
	while ($row=mysql_fetch_assoc($result)){
		$villes .=$row['ville'].",";
	}
	$villes=substr_replace($villes, '', -1);
	$villes=explode(",",$villes);
	return $villes;
}

function test(){
	$query="select para1 from residence where id_residence=1";
	$result=runQuery($query);
	$row=mysql_fetch_assoc($result);
	$val=$row['para1'];
	return $val;
}

function getVilleList(){
 $villeList="<tr>
	<td><label for='villeList'>Ville </label></td>
	<td><select id='villeList'><option value='' selected='selected'></option>";
 $villes=getVille();
 foreach ($villes as $ville) {
 	$villeList .="<option value=$ville>$ville</option>";
 }
 $villeList .="</select></td></tr>";

return $villeList;
}
function getResidenceList($ville){
	$query="SELECT `id_residence`,`nom_residence` FROM `residence` WHERE ville='$ville'";
	$result=runQuery($query);
	$List="<tr>
	<td><label for='idresidence'>Residence</label></td>
	<td><select id='idresidence'>
	<option value='' selected='selected'></option>";
	while ($rows=mysql_fetch_array($result,MYSQL_ASSOC)){
	$idresidence=$rows['id_residence'];
	$nomresidence=$rows['nom_residence'];
	$List .="<option value='$idresidence'>$nomresidence</option>";		
	}
	$List .="</select></td></tr>";
	return $List;
}

function getMessageTypeList(){
	$query="select * from message_types";
	$result=runQuery($query);
	$selectList="<select id='selected_nom_message_type'>";
	while ($rows=mysql_fetch_array($result,MYSQL_ASSOC)){
		$selectedValue=$rows['idmessage_types'];
		$selectList .= "<option value='$selectedValue'>". $rows['nom_message_type']."</option>";
	}
	$selectList .="</select>";
return $selectList;	
}
//check
function getEtendueMessageList(){
	$etendueList="<select id='id_message_etendue'>
					<option value='1'>  juste dans cette residence</option>
					<option value='2'>  juste dans ta ville</option>
					<option value='3'>  partout</option>
				</select>";
	return $etendueList;
}
function getGroupeList(){
	$groupeList="<select id='nom_groupe'>";

	$query="select * from groupe ";
	$result=runQuery($query);
	while ($rows=mysql_fetch_array($result)){
		$value=$rows['id_groupe'];
		$groupeList .="<option value='$value'>".$rows['nom_groupe']."</option>";
	}
	$groupeList .="</select>";
	return $groupeList;
}